Skip to content

Conversation

@ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented Jan 14, 2026

Proposed changes (Including videos or screenshots)

As per CORE-1625, this PR adds support for sending multiple file attachments via the /sendEmailAttachment slash command.

Previously, when a message contained multiple files, only the first file would be sent as an email attachment. With this change, all files attached to the message are included in the email.

Issues

Steps to test or reproduce

Prerequisites

  • Rocket.Chat running locally
  • Omnichannel enabled

1. Set up email testing environment

Create a docker-compose.mail-test.yml file:

version: '3.8'

services:
  greenmail:
    image: greenmail/standalone:2.0.0
    container_name: greenmail
    ports:
      - "3025:3025"   # SMTP
      - "3143:3143"   # IMAP
    networks:
      - mail-network

  roundcube:
    image: roundcube/roundcubemail
    container_name: roundcube
    ports:
      - "8080:80"
    environment:
      - ROUNDCUBEMAIL_DEFAULT_HOST=greenmail
      - ROUNDCUBEMAIL_DEFAULT_PORT=3143
      - ROUNDCUBEMAIL_SMTP_SERVER=greenmail
      - ROUNDCUBEMAIL_SMTP_PORT=3025
    depends_on:
      - greenmail
    networks:
      - mail-network

networks:
  mail-network:
    driver: bridge

Start the containers:

docker-compose -f docker-compose.mail-test.yml up -d

2. Configure email inbox in Rocket.Chat

  1. Go to Administration → Email Inboxes (/admin/email-inboxes)
  2. Click + New Email Inbox
  3. Configure the inbox:
    • Name: Test Inbox
    • Email: test@localhost
    • SMTP Server: localhost
    • SMTP Port: 3025
    • SMTP Security: None
    • IMAP Server: localhost
    • IMAP Port: 3143
    • IMAP Security: None
    • Username / Password: test@localhost / test
      (GreenMail auto-creates accounts)
  4. Save and verify the connection

3. Test single file attachment (baseline)

  1. Send an email to test@localhost using Roundcube (http://localhost:8080)
    • Login with any email (e.g. visitor@test.com / visitor)
    • Compose and send an email to test@localhost
  2. A new Omnichannel room should be created in Rocket.Chat
  3. As an agent, upload one file to the room
  4. Click “Send via Email as attachment”
  5. Open Roundcube, log in as visitor@test.com, and verify:
    • The email was received
    • Exactly one attachment is present

4. Test multiple file attachments (new feature)

  1. In the same Omnichannel room, upload multiple files at once
    • Example: 2–3 images or documents
  2. Click “Send via Email as attachment”
  3. Open Roundcube and verify:
    • The email was received successfully
    • All uploaded files are attached (not only the first one)
    • File names are correct
    • Files can be downloaded and opened

Summary by CodeRabbit

  • Bug Fixes

    • Fixed sending multiple file attachments in a single outgoing email so messages can include several attachments reliably.
  • New Features

    • Added batch retrieval support for uploads to improve multi-file handling and performance.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 14, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

🦋 Changeset detected

Latest commit: b41f2cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@rocket.chat/model-typings Patch
@rocket.chat/models Patch
@rocket.chat/meteor Patch
@rocket.chat/apps Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/omnichannel-services Patch
rocketchat-services Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/ui-client Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/media-calls Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/presence Patch
@rocket.chat/network-broker Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

Walkthrough

Refactors outgoing email handling to support multiple file attachments by batching upload retrieval and building Mail.Attachments; adds findByIds to the Upload model API; adds a changeset documenting the patch across three Rocket.Chat packages. (49 words)

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/chatty-camels-explain.md
Adds a changeset entry documenting the patch that updates three Rocket.Chat packages to fix multiple file attachments in sendEmailAttachment.
Email Outgoing Feature
apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts
Adds IUpload import and isTruthy; introduces buildMailAttachment(file: IUpload); refactors sendEmailAttachment to derive fileRefs from message.files/message.file, call findByIds, batch FileUpload.getBuffer for each upload, compose emailText from attachment descriptions, and send email with multiple attachments.
Upload Model API
packages/model-typings/src/models/IBaseUploadsModel.ts, packages/models/src/models/BaseUploadModel.ts
Adds findByIds(_ids: string[], options?: FindOptions<T>): FindCursor<T> to the interface and implements it in BaseUploadModel to support bulk retrieval by IDs.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/Command
    participant EmailBox as EmailInbox Service
    participant Uploads as Uploads Model
    participant FileUpload as FileUpload Service
    participant Mail as Mail Service

    User->>EmailBox: invoke sendEmailAttachment(message, room)
    EmailBox->>EmailBox: extract fileRefs from message.files / message.file
    EmailBox->>Uploads: findByIds(fileRefs)
    Uploads-->>EmailBox: returns IUpload[] 

    loop for each upload
        EmailBox->>FileUpload: getBuffer(upload)
        FileUpload-->>EmailBox: returns buffer
        EmailBox->>EmailBox: buildMailAttachment(upload, buffer)
    end

    EmailBox->>EmailBox: compose emailText from attachment descriptions
    EmailBox->>Mail: send email with attachments + emailText (+ inReplyTo/references)
    Mail-->>EmailBox: send result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • KevLehman
  • tassoevan

Poem

🐰 Hopped through code to stitch files in a row,
Now many attachments together can go.
Buffers fetched, descriptions aligned,
One email sent — no file left behind. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding multiple file support to /sendEmailAttachment.
Linked Issues check ✅ Passed The PR successfully implements support for multiple file attachments in /sendEmailAttachment as required by CORE-1625.
Out of Scope Changes check ✅ Passed All changes are directly scoped to enabling multiple file attachments in the /sendEmailAttachment command and supporting infrastructure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/send-email-attachment-support-multi-files


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 94623c7 and c11768c.

📒 Files selected for processing (1)
  • apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.70%. Comparing base (30a28d6) to head (b41f2cc).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38183      +/-   ##
===========================================
- Coverage    70.73%   70.70%   -0.03%     
===========================================
  Files         3147     3147              
  Lines       108874   108882       +8     
  Branches     19597    19574      -23     
===========================================
- Hits         77007    76982      -25     
- Misses       29863    29896      +33     
  Partials      2004     2004              
Flag Coverage Δ
e2e 60.23% <ø> (+0.02%) ⬆️
e2e-api 47.29% <0.00%> (-1.12%) ⬇️
unit 71.84% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 14, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/15 19:45 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38183
  • Baseline: develop
  • Timestamp: 2026-01-15 19:45:41 UTC
  • Historical data points: 30

Updated: Thu, 15 Jan 2026 19:45:42 GMT

@ricardogarim ricardogarim marked this pull request as ready for review January 14, 2026 16:59
@ricardogarim ricardogarim requested review from a team as code owners January 14, 2026 16:59
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts`:
- Around line 150-165: sendEmail may resolve to undefined on failure, so the
chained .then((info) => LivechatRooms.updateEmailThreadByRoomId(room._id,
info.messageId)) can throw when info is undefined; update the call site around
sendEmail to handle failures explicitly — either await sendEmail inside a
try/catch and only call LivechatRooms.updateEmailThreadByRoomId on a successful
result, or chain a .catch to log/handle the error and guard the .then with a
null check (e.g. only call LivechatRooms.updateEmailThreadByRoomId when info is
truthy). Ensure you reference sendEmail and
LivechatRooms.updateEmailThreadByRoomId in the fix.
🧹 Nitpick comments (1)
apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts (1)

137-142: Consider using the new findByIds method for consistency.

The PR adds findByIds to the Uploads model, but this code uses a direct find with $in. Using the new method would align with the model changes and improve readability.

Suggested change
-		const files = await Uploads.find({ _id: { $in: fileRefs.map((f) => f._id) } }).toArray();
+		const files = await Uploads.findByIds(fileRefs.map((f) => f._id)).toArray();
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 28a8d39 and 94623c7.

📒 Files selected for processing (4)
  • .changeset/chatty-camels-explain.md
  • apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts
  • packages/model-typings/src/models/IBaseUploadsModel.ts
  • packages/models/src/models/BaseUploadModel.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/models/src/models/BaseUploadModel.ts
  • packages/model-typings/src/models/IBaseUploadsModel.ts
  • apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts
🧬 Code graph analysis (1)
apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts (2)
packages/core-typings/src/IRoom.ts (1)
  • IOmnichannelRoom (269-320)
packages/models/src/index.ts (2)
  • Uploads (202-202)
  • LivechatRooms (167-167)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (6)
packages/models/src/models/BaseUploadModel.ts (1)

95-103: LGTM!

The findByIds implementation is clean and follows the established patterns in this model class. The $in query is the standard MongoDB approach for batch retrieval by IDs.

packages/model-typings/src/models/IBaseUploadsModel.ts (1)

13-14: LGTM!

The interface addition is correctly typed and aligns with the implementation in BaseUploadModel.ts.

apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.ts (3)

25-35: LGTM!

The buildMailAttachment helper is well-structured: it correctly handles the case where no buffer is available and returns a properly typed Mail.Attachment object.


117-120: LGTM!

Good backward compatibility handling—supports both the newer message.files array and the legacy message.file single-file format.


144-148: LGTM!

Composing the email body from attachment descriptions is a reasonable approach for multi-attachment messages.

.changeset/chatty-camels-explain.md (1)

1-7: LGTM!

The changeset correctly identifies all affected packages and accurately describes the fix.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@ricardogarim ricardogarim added the stat: QA assured Means it has been tested and approved by a company insider label Jan 15, 2026
@tassoevan tassoevan added stat: QA assured Means it has been tested and approved by a company insider and removed stat: QA assured Means it has been tested and approved by a company insider labels Jan 15, 2026
@dionisio-bot dionisio-bot bot removed the stat: QA assured Means it has been tested and approved by a company insider label Jan 15, 2026
@tassoevan tassoevan added the stat: QA assured Means it has been tested and approved by a company insider label Jan 15, 2026
@alfredodelfabro alfredodelfabro added this to the 8.1.0 milestone Jan 15, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jan 15, 2026
@kodiakhq kodiakhq bot merged commit f4fa393 into develop Jan 15, 2026
44 checks passed
@kodiakhq kodiakhq bot deleted the fix/send-email-attachment-support-multi-files branch January 15, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants